package com.android.qjpmc.manager;

import android.content.Intent;

import com.android.qjpmc.widget.utils.ToastUtils;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import androidx.fragment.app.FragmentActivity;

/**
 * Created by Administrator on 2019/5/6.
 */

public class UMShareManager {
    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {

        }

        @Override
        public void onResult(SHARE_MEDIA share_media) {

        }

        @Override
        public void onError(SHARE_MEDIA share_media, Throwable throwable) {
            ToastUtils.showShort(throwable.getMessage());
        }

        @Override
        public void onCancel(SHARE_MEDIA share_media) {

        }
    };

    private UMShareManager() {

    }


    private static class UMShareManagerSingleton {
        private static final UMShareManager INSTANCE = new UMShareManager();

    }

    public static UMShareManager getInstance() {
        return UMShareManagerSingleton.INSTANCE;
    }

    public void shareRegisterWx(FragmentActivity activity) {
    }

    public void shareRedpackageWx(FragmentActivity activity) {
    }

    public void shareRedpackageWxCirCle(FragmentActivity activity) {
    }

    public void shareWx(FragmentActivity activity, String url, String title, String desc, UMImage image) {
        share(activity, SHARE_MEDIA.WEIXIN, url, title, desc, image);
    }

    public void shareWx(FragmentActivity activity, String url, String title, String desc, String image) {
        share(activity, SHARE_MEDIA.WEIXIN, url, title, desc, new UMImage(activity, image));
    }

    public void shareQQ(FragmentActivity activity, String url, String title, String desc, UMImage image) {
        share(activity, SHARE_MEDIA.QQ, url, title, desc, image);
    }

    public void shareQQ(FragmentActivity activity, String url, String title, String desc, String image) {
        share(activity, SHARE_MEDIA.QQ, url, title, desc, new UMImage(activity, image));
    }

    public void shareQZone(FragmentActivity activity, String url, String title, String desc, UMImage image) {
        share(activity, SHARE_MEDIA.QZONE, url, title, desc, image);
    }

    public void shareQZone(FragmentActivity activity, String url, String title, String desc, String image) {
        share(activity, SHARE_MEDIA.QZONE, url, title, desc, new UMImage(activity, image));
    }

    public void shareSINA(FragmentActivity activity, String url, String title, String desc, UMImage image) {
        share(activity, SHARE_MEDIA.SINA, url, title, desc, image);
    }

    public void shareSINA(FragmentActivity activity, String url, String title, String desc, String image) {
        share(activity, SHARE_MEDIA.SINA, url, title, desc, new UMImage(activity, image));
    }

    public void shareWxCirCle(FragmentActivity activity, String url, String title, String desc, UMImage image) {
        share(activity, SHARE_MEDIA.WEIXIN_CIRCLE, url, title, desc, image);
    }

    public void shareWxCirCle(FragmentActivity activity, String url, String title, String desc, String image) {
        share(activity, SHARE_MEDIA.WEIXIN_CIRCLE, url, title, desc, new UMImage(activity, image));
    }


    public void share(FragmentActivity activity, SHARE_MEDIA media, String url, String title, String desc, UMImage image) {
        new ShareAction(activity)
                .setPlatform(media)//传入平台

                .withMedia(new UMWeb(url, title, desc, image))
                .setCallback(umShareListener)//回调监听器
                .share();
    }

    public void onActivityResult(FragmentActivity activity, int requestCode, int resultCode, Intent data) {
        UMShareAPI.get(activity).onActivityResult(requestCode, resultCode, data);
    }

}
